import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children: [
      {
        path: '/home',
        name: 'about',
        component: () => import('../views/AboutView.vue')
      },
      {
        path: '/users',
        name: 'users',
        component: () => import('../views/users.vue')
      },
    ]
  },

  {
    path: '/',
    name: 'login',
    component: () => import('../views/login.vue')
  }
]

const router = new VueRouter({
  routes
})

// 访问的白名单, 可以直接通行
// router.beforeEach((to, from, next) => {
//   let token = window.localStorage.getItem('token')
//   if (to.path == '/home') {
//     if (token) {
//       next()
//     } else {
//       next('/')
//     }
//   } else {
//     if (token) {
//       next()
//     } else {
//       next('/')
//     }
//   }
// })


export default router
